# encoding=utf8
# author: allen
# create_time: 2024/5/6 16:52
# file: node.py

from blockchain.chain import Chain


class Node(object):
    def __init__(self, node_id=1):
        self.chain = Chain(node_id)
        self.name = 'node {}'.format(node_id)

    def mine(self, data):
        new_block = self.chain.mine(data)
        return new_block

    def replace_chain(self, new_chain):
        self.chain.replace_chain(new_chain)

    def get_chain(self):
        return self.chain.to_dict()

    def sync_data(self, data, node_list):
        for node in node_list:
            node.chain.add_chain_only(data)


if __name__ == '__main__':
    node = Node()
    # print(node.get_chain())
